import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args){
    Scanner scanner=new Scanner(System.in);
    System.out.println("Please input this Fibonacci n:");
    int n=scanner.nextInt();//假设输入大于零的整数
    float q=fibonacci(n)/fibonacciNormal(n );
    System.out.printf("第%d个Fibonacci数与它后一项之比为：%.6f%n",n,q);
    float sum=0;
    for(int i=1;i<=n;i++){
        sum+=fibonacci(i);
    }
    System.out.printf("第%d个Fibonacci数是：%2.0f%n",n,fibonacci(n));
    System.out.printf("前%d个Fibonacci数之和是：%2.0f%n",n,sum);
    System.out.printf("前%d个Fibonacci数为：",n);
    for(int i=1;i<=n;i++){
        System.out.printf("%2.0f\t",fibonacci(i));
    }
}
//递归实现方法
public static float fibonacci(int n){
    if(n<=2){
        return 1;
    }
    else{
        return fibonacci(n-1)+fibonacci(n-2);
    }
}
//递推实现方法
public static float fibonacciNormal(int n){
    if(n<=2){
        return 1;
    }
    int n1=1,n2=1,sn=0;
    for(int i=0;i<=n-2;i++){
        sn=n1+n2;
        n1=n2;
        n2=sn;
    }
    return sn;
}
}
